package com.itypd.thread;

/*
 * @Description:
 * @Athor: GongMingwei
 * @version: v1.0
 */
public class WaitTest {
    static Object o = null;
    public static void main(String[] args) {
        o = new Object();
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                while(true){
                    synchronized (o){
                        try {
                            System.out.println(Thread.currentThread()+" go wait");
                            o.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        });
        Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                while(true){
                    synchronized (o){
                        try {
                            System.out.println(Thread.currentThread()+" go wait");
                            o.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                while(true){
                    synchronized (o){
                        System.out.println(Thread.currentThread()+" go up");
                        o.notifyAll();
                    }
                }
            }
        });
        t1.start();
        t2.start();
        t3.start();
    }
}
